/**
 * @author
 * Júlio Zynger
 * DRE: 110092466
 */
package view;

import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;

import javax.swing.*;

@SuppressWarnings("serial")
public class DinamicJTextArea extends JPanel implements ActionListener {
    protected JTextField textField;
    protected JTextArea textArea;
    protected ArrayList<String> conteudo;
    private final static String newline = "\n";

    public DinamicJTextArea(String tooltip) {
        super(new GridBagLayout());
        
        conteudo = new ArrayList<String>();
        textField = new JTextField(20);
        textField.setToolTipText(tooltip);
        textField.addActionListener(this);

        textArea = new JTextArea(5, 20);
        textArea.setEditable(false);
        JScrollPane scrollPane = new JScrollPane(textArea);

        GridBagConstraints c = new GridBagConstraints();
        c.gridwidth = GridBagConstraints.REMAINDER;

        c.fill = GridBagConstraints.HORIZONTAL;
        add(textField, c);

        c.fill = GridBagConstraints.BOTH;
        c.weightx = 1.0;
        c.weighty = 1.0;
        add(scrollPane, c);
    }

    public void actionPerformed(ActionEvent evt) {
        String text = textField.getText();
        textArea.append(text + newline);
        this.conteudo.add(text);
        textField.selectAll();
        
        textArea.setCaretPosition(textArea.getDocument().getLength());
    }

	public ArrayList<String> getConteudo() {
		return conteudo;
	}
    
    
}